/*
============================================================================
 Name        : BlockCard.cpp
 Author      : 
 Version     :
 Copyright   : 
 Description : CBlockCard implementation
============================================================================
*/

#include "BlockCard.h"
#include "Global.h"
#include "eStockappui.h"
#include "BlockMenu.h"
#include <eStock_L2hy.rsg>
#include "BlockMemo.h"
#include <hash.h>
#include <utf.h>
#include "cntrlcommfun.h"

#ifndef	MOBILEMARKET

CBlockCard::CBlockCard(CBaseBlock* bsBack,const TInt& nType):
CBlock(bsBack),
m_nType(nType),
m_nCurrent(0),
m_postData(NULL)
{
	// No implementation required
}


CBlockCard::~CBlockCard()
{
	m_Ctrls.ResetAndDestroy();
	m_Ctrls.Close();
	delete m_postData;

	if(m_vTip1 != NULL)
	{
		m_vTip1->Reset();
		delete m_vTip1;
	}
	if(m_vTip2 != NULL)
	{
		m_vTip2->Reset();
		delete m_vTip2;
	}
	if(m_vTip3 != NULL)
	{
		m_vTip3->Reset();
		delete m_vTip3;
	}
}

CBlockCard* CBlockCard::NewLC(CBaseBlock* bsBack,const TInt& nType)
{
	CBlockCard* self = new (ELeave)CBlockCard(bsBack,nType);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CBlockCard* CBlockCard::NewL(CBaseBlock* bsBack,const TInt& nType)
{
	CBlockCard* self=CBlockCard::NewLC(bsBack,nType);
	CleanupStack::Pop(); // self;
	return self;
}

void CBlockCard::ConstructL()
{
	CBlock::ConstructL();
	CGlobal::GetDesFromID(m_strOK,LOC_BUF_MENU_CHARGE);

	CGlobal::GetDesFromID(m_strErrCard,LOC_BUF_STR_ERRCARD);
	CGlobal::GetDesFromID(m_strErrPw,LOC_BUF_STR_ERRPW);
	
	TBuf<8> bufcard;
	CGlobal::GetDesFromID(bufcard,LOC_BUF_STR_NCARD);
	TBuf<8> bufpw;
	CGlobal::GetDesFromID(bufpw,LOC_BUF_STR_PASSWORD);
	TBuf<8> bufsales;
	CGlobal::GetDesFromID(bufsales,LOC_BUF_STR_SALES);

	if(m_nType == 2)
	{
		m_selBox = CSelectBox::NewL();
		m_selBox->AddItem(5000,LOC_BUF_MENU_50YUAN);
		m_selBox->AddItem(10000,LOC_BUF_MENU_100YUAN);
		m_selBox->AddItem(30000,LOC_BUF_MENU_300YUAN);
		m_selBox->AddItem(50000,LOC_BUF_MENU_500YUAN);
		m_inputCard = CSingleLineTextInput::NewL(bufcard,17);
		m_inputPwd = CSingleLineTextInput::NewL(bufpw,18);
		m_Ctrls.Append(m_selBox);
	}
	else
	{
		CGlobal::GetDesFromID(m_tip2,LOC_BUF_STR_YEARCARDTIP2);
		m_vTip2 = new(ELeave)CDesC16ArrayFlat(4);
		if(m_vTip2 != NULL)
		{
			CreateTipArray(m_tip2,*m_vTip2);
		}
		CGlobal::GetDesFromID(m_tip3,LOC_BUF_STR_YEARCARDTIP3);
		m_vTip3 = new(ELeave)CDesC16ArrayFlat(4);
		if(m_vTip3 != NULL)
		{
			CreateTipArray(m_tip3,*m_vTip3);
		}

		TBuf<16> temp;
		m_inputCard = CSingleLineTextInput::NewL(bufcard,11);
		CGlobal::GetDesFromID(temp, LOC_BUF_STR_YEARCARDTIP4);
		m_inputCard->SetEmtpyString(temp);
		m_inputPwd = CSingleLineTextInput::NewL(bufpw,6);
		m_inputPwd->SetEmtpyString(temp);

		TBuf<8> productcard;
		CGlobal::GetDesFromID(temp, LOC_BUF_STR_INPUTTIP2);
		CGlobal::GetDesFromID(productcard,LOC_BUF_STR_PRODUCTCARD);
		m_ProductCard = CSingleLineTextInput::NewL(productcard,20);
		m_ProductCard->SetEmtpyString(temp);
		m_ProductPwd = CSingleLineTextInput::NewL(bufpw,20);
		m_ProductPwd->SetEmtpyString(temp);
	}

	CGlobal::GetDesFromID(m_tip1,LOC_BUF_STR_YEARCARDTIP1);
	m_tip1.Append(m_pGlobal->m_strUserName);
	m_vTip1 = new(ELeave)CDesC16ArrayFlat(4);
	if(m_vTip1!=NULL)
	{
		CreateTipArray(m_tip1,*m_vTip1);
	}

	m_Ctrls.Append(m_inputCard);
	m_Ctrls.Append(m_inputPwd);
	if (m_nType == 1)
	{
		m_Ctrls.Append(m_ProductCard);
		m_Ctrls.Append(m_ProductPwd);
	}

	if (CGlobal::Static()->m_osMajor == 3)
		m_Ctrls[0]->SetFocus(ETrue);

	m_bSocketed = ETrue;
}


void CBlockCard::SizeChanged()
{
	CBlock::SizeChanged();
	iToolbar->SetSoftKey(CToolbar::EOK, CToolbar::EBack);
	if(m_vTip1!=NULL)
	{
		CreateTipArray(m_tip1,*m_vTip1);
	}
	if(m_vTip2 != NULL)
	{
		CreateTipArray(m_tip2,*m_vTip2);
	}
	if(m_vTip3!=NULL)
	{
		CreateTipArray(m_tip3,*m_vTip3);
	}

	if (m_vTip1 != NULL && m_vTip2 != NULL && m_nType == 1)
	{
		TInt n = m_vTip1->MdcaCount();
		for (int i = 0; i<2; i++, n++)
		{
			TInt y = (n+1)*(m_nLineHeight+4);
			m_Ctrls[i]->SetRect(0, y, m_nScreenWidth, y+m_nLineHeight-1);
		}
		n += m_vTip2->MdcaCount();
		for (int i = 2; i<4; i++, n++)
		{
			TInt y = (n+1)*(m_nLineHeight+4);
			m_Ctrls[i]->SetRect(0, y, m_nScreenWidth, y+m_nLineHeight-1);
		}
	}
	if (m_vTip1 != NULL &&m_nType == 2)
	{
		TInt n = m_vTip1->MdcaCount();
		for (int i = 0; i<m_Ctrls.Count(); i++, n++)
		{
			TInt y = (n+1)*(m_nLineHeight+4);
			m_Ctrls[i]->SetRect(0, y, m_nScreenWidth, y+m_nLineHeight-1);
		}
	}
}

void CBlockCard::BeforeDraw(CFbsBitGc& g) const
{
//	TBuf<10> temp;
//	if(m_nCurrent>0)
//	{
//		CSingleLineTextInput* input = (CSingleLineTextInput*)m_Ctrls[m_nCurrent];
//		TInt nLen = input->GetTextLength();
//		TInt nMax = input->GetMaxLength();
//		temp.Format(_L("(%d/%d)"),nLen,nMax);
//	}

	if(m_nType == 2)
		CGlobal::GetDesFromID(m_strTitle, LOC_BUF_MENU_CARDSZX);
	else
		CGlobal::GetDesFromID(m_strTitle, LOC_BUF_MENU_CARDCHARGE);
//	m_strTitle.Append(temp);

	iTitlebar->SetTitleText(m_strTitle);
	CBlock::BeforeDraw(g);
}

void CBlockCard::OnDraw(CFbsBitGc& g) const
{
	TBuf<32> str;

	TInt nTop = m_rect.iTl.iY;
	if (m_vTip1 != NULL)
	{
		for (TInt i = 0; i < m_vTip1->MdcaCount(); ++i)
		{
			TInt nY = nTop+m_nLineHeight*i;
			TRgb rgb = m_pGlobal->g_rgbText;
			str.Copy((*m_vTip1)[i]);

			CGlobal::DrawString(g,str,2,nY,TOP|LEFT,rgb);
		}
	}
	nTop = m_Ctrls[1]->m_rect.iBr.iY;
	if (m_nType == 1 && m_vTip2 != NULL && m_vTip3 != NULL)
	{
		for (TInt i = 0; i < m_vTip2->MdcaCount(); ++i)
		{
			TInt nY = nTop+m_nLineHeight*i;
			TRgb rgb = m_pGlobal->g_rgbText;
			str.Copy((*m_vTip2)[i]);

			CGlobal::DrawString(g,str,2,nY,TOP|LEFT,rgb);
		}
		nTop = m_Ctrls[3]->m_rect.iBr.iY;
		for (TInt i = 0; i < m_vTip3->MdcaCount(); ++i)
		{
			TInt nY = nTop+m_nLineHeight*i;
			TRgb rgb = m_pGlobal->g_rgbText;
			str.Copy((*m_vTip3)[i]);

			CGlobal::DrawString(g,str,2,nY,TOP|LEFT,rgb);
		}
	}

	for(TInt i=0; i<m_Ctrls.Count(); i++)
		m_Ctrls[i]->Draw(g);

//	if (m_nType == 1 && (m_ProductCard->m_bIsActive || m_ProductPwd->m_bIsActive))
//	{
//		TBuf<16> inputTip;
//		CGlobal::GetDesFromID(inputTip, LOC_BUF_STR_INPUTTIP);
//		TBuf<4> numOrLetter;
//
//		CSingleLineTextInput* input = NULL;
//		if (m_ProductCard->m_bIsActive)
//			input = m_ProductCard;
//		else if (m_ProductPwd->m_bIsActive)
//			input = m_ProductPwd;
//
//		if (input->GetTextInput()->m_bNumber)
//			CGlobal::GetDesFromID(numOrLetter, LOC_BUF_MENU_LETTER);
//		else
//			CGlobal::GetDesFromID(numOrLetter, LOC_BUF_MENU_DIGITAL);
//		inputTip.Append(numOrLetter);
//
//		TInt nY = m_Ctrls[m_Ctrls.Count() - 1]->m_rect.iBr.iY;
//		if (!m_pGlobal->m_bSupportTouch)
//			CGlobal::DrawString(g, inputTip, 2, nY, TOP|LEFT, CGlobal::Static()->g_rgbText);
//	}
}

void CBlockCard::OnKeyEvent(const TInt& keyCode)
{
	if (keyCode==m_pGlobal->g_nKeyOK/* || keyCode==EStdKeyNkpAsterisk || keyCode == '*'*/)
	{
		m_inputCard->GetText(m_strCard);
		m_inputPwd->GetText(m_strCardPWD);
		if(m_nType == 1)
		{
			m_ProductCard->GetText(m_strProductCard);
			m_ProductCard->GetText(m_strProductPWD);
		}
		
		if(m_nType == 2)
			PackageData();

		if (m_inputCard->GetTextLength()==0 )
		{
			m_nCurrent = 0;
			ShowAlert(m_strErrCard, this);
		}
		else if (m_inputPwd->GetTextLength()==0 )
		{
			m_nCurrent = 1;
			ShowAlert(m_strErrPw, this);
		}
		else
		{	
			TBuf<128> bufformat;
			TBuf<128> buf;
			CGlobal::GetDesFromID(bufformat,LOC_BUF_STR_YEARCARDTIP6);
			buf.Format(bufformat, &(m_pGlobal->m_strUserName));
			TBuf<8> title;
			CGlobal::GetDesFromID(title,LOC_BUF_STR_YEARCARDTIP5);
			if (0 != CntrlCommFun::ShowConfirmationQueryL(buf,
					m_pGlobal->g_rgbText, m_pGlobal->g_rgbBackGround,
					m_pGlobal->g_rgbHighlight, EOKCancel, title))
			{
				m_bSocketed = EFalse;
				StartSocket();
			}
		}
		return;
	}
	if (keyCode==m_pGlobal->g_nKeyUp || keyCode==m_pGlobal->g_nKeyDown)
	{
		m_Ctrls[m_nCurrent]->SetFocus(EFalse);
		if (keyCode==m_pGlobal->g_nKeyUp)
		{
			m_nCurrent--;
			if (m_nCurrent<0)
				m_nCurrent = m_Ctrls.Count()-1;
		}
		else
		{
			m_nCurrent++;
			if (m_nCurrent>=m_Ctrls.Count())
				m_nCurrent = 0;
		}
		m_Ctrls[m_nCurrent]->SetFocus(ETrue);
		DrawNow();
		return;
	}
	if ((keyCode=='#' || keyCode==EStdKeyHash) && m_nType == 1)
	{
		if (m_ProductCard->Focus())
		{
		    CGlobal::Static()->g_bNumvber = !CGlobal::Static()->g_bNumvber;
			CTextInput* input = m_ProductCard->GetTextInput();
			input->m_bNumber = CGlobal::Static()->g_bNumvber;//!input->m_bNumber;
#ifdef __SERIES60_3X__
			GetContainer()->SetInputNumber(input->m_bNumber);
#endif
		} 
		else if (m_ProductPwd->Focus())
		{
			CTextInput* input = m_ProductPwd->GetTextInput();
			input->m_bNumber = !input->m_bNumber;
#ifdef __SERIES60_3X__
			GetContainer()->SetInputNumber(input->m_bNumber);
#endif
		}
		DrawNow();
		return;
	}
	if (keyCode==m_pGlobal->g_nKeyCancel)
	{
		if (!m_bSocketed)
		{
			//m_bDoLogin = EFalse;
			StopSocket();
			DrawNow();
		}
		else
			GetContainer()->AddBlock(NULL);
		return;
	}
	if(m_Ctrls[m_nCurrent]->OnKeyDown(keyCode))
	{
		DrawNow();
		return;
	}
	CBlock::OnKeyEvent(keyCode);
}


TBool CBlockCard::ReadData(const TDesC8& aData)
{
	TPtrC8 ptr(aData);
	//m_bDoLogin = EFalse;
	if(m_nType == 1)
	{
		if (!m_bExit)
		{
			TInt32 nError = CGlobal::ReadInt32L(ptr);
			HBufC* strError = CGlobal::ReadStringL(ptr);
			if (nError==0)
				GetContainer()->AddBlock(CBlockMemo::NewL(this, 500, strError->Des()));
			else
				GetContainer()->AddBlock(CBlockMemo::NewL(this, 501, strError->Des()));
			delete strError;
		}
	}
	else
	{
		HBufC* strError = CnvUtfConverter::ConvertToUnicodeFromUtf8L(ptr);
		TInt nStart = 0;
		TInt nEnd = 0;
	
		TPtrC ptr(strError->Des());
		nStart = ptr.FindF(_L("<p>"));
		nEnd = ptr.FindF(_L("<br/>"));
		if(nStart!=KErrNotFound && nEnd!=KErrNotFound)
		{
			nStart+=3;
			ptr.Set(ptr.Mid(nStart,nEnd-nStart));
		}
		else
		{
			nStart = ptr.FindF(_L("\3"));
			nEnd = ptr.FindF(_L("&"));
			if(nStart!=KErrNotFound && nEnd!=KErrNotFound)
			{
				nStart+=1;
				ptr.Set(ptr.Mid(nStart,nEnd));
			}
		}
		TBuf<256> buf;
		CGlobal::GetDesFromID(buf,LOC_BUF_STR_SZXCHARGED);
		buf.Insert(0,ptr);
		GetContainer()->AddBlock(CBlockMemo::NewL(this, 500, buf));
		delete strError;
	}
	m_bSocketed = ETrue;
	m_bExit = ETrue; //\x{672c}\x{7c7b}\x{53ea}\x{6536}\x{4e00}\x{904d}\x{6570}\x{636e}
	return ETrue;
}

void CBlockCard::WriteData(TDes8& aBuf)
{
	if(m_nType == 1)
	{
		CGlobal::WriteString(aBuf, m_pGlobal->m_strUserName);
		CGlobal::WriteString(aBuf, m_strCard);
		CGlobal::WriteString(aBuf, m_strCardPWD);
		CGlobal::WriteInt32L(aBuf,KConstMajorVersion);
		CGlobal::WriteString(aBuf, m_strProductCard);
		CGlobal::WriteString(aBuf, m_strProductPWD);
	}
	else
	{
		aBuf.Append(m_postData->Des());
	}

	//m_bDoLogin = ETrue;
	DrawNow();
}

TInt CBlockCard::GetDataLength()
{
	if(m_nType == 1)
	{
		return CGlobal::GetWriteLength(m_pGlobal->m_strUserName)+
			CGlobal::GetWriteLength(m_strCard)+
			CGlobal::GetWriteLength(m_strCardPWD) + 4 +
			CGlobal::GetWriteLength(m_strProductCard) + 
			CGlobal::GetWriteLength(m_strProductPWD);
	}
	else if(m_nType==2)
		return m_postData->Length();
	else 
		return 0;
}

TInt16 CBlockCard::GetDataType()
{
	if (m_bSocketed)
		return RequestDataType_None;
	else
		return RequestDataType_Card;
}

TInt CBlockCard::GetIOType()
{
	if(m_nType == 1)
		return 0;
	else if(m_nType == 2)
		return 3;
	return 0;
}

TBool CBlockCard::MustLogin()
{
	return EFalse;
}

void CBlockCard::OnMouseUp(const TPoint& aPt)
{
	TInt nPos = -1;
	for(TInt i=0; i<m_Ctrls.Count(); i++)
	{
		TInt top = m_Ctrls[i]->m_rect.iTl.iY;
		TInt bottom = m_Ctrls[i]->m_rect.iBr.iY;
		if (aPt.iY>top && aPt.iY<bottom)
		{
			nPos = i;
			break;
		}
	}
	if (nPos>=0)
	{
		m_Ctrls[m_nCurrent]->SetFocus(EFalse);
		m_nCurrent = nPos;
		m_Ctrls[m_nCurrent]->SetFocus(ETrue);
		if (m_nType == 1)
		{
			if (nPos == 1 || nPos == 3)
				m_kb->SetInputType(CKeyBoard::PASSWORD);
		}
		else if (m_nType == 2)
		{
			if (nPos == 1 || nPos == 2)
				m_kb->SetInputType(CKeyBoard::NUMERIC);
			if (m_Ctrls[m_nCurrent] == m_selBox)
			{
				if (aPt.iX<m_nLineHeight)
					OnKeyEvent(m_pGlobal->g_nKeyLeft);
				else if (aPt.iX>m_nScreenWidth-m_nLineHeight)
					OnKeyEvent(m_pGlobal->g_nKeyRight);
			}
		}
		DrawNow();
	}
}

void CBlockCard::OnInput(const TDesC8& strInput)
{
	if (m_kb->m_bInputGoodCode)
	{
		CBlock::OnInput(strInput);
		return;
	}
	
	TBuf<32> buf;
	buf.Copy(strInput);
	static_cast<CSingleLineTextInput*>(m_Ctrls[m_nCurrent])->SetText(buf);
	DrawNow();
}

void CBlockCard::AppendParamall(HBufC8*& aBuf,const TDesC8& aFieldName,
									 const TDesC8& aFieldValue) 
{
	if(aBuf == NULL)
	{
		aBuf = HBufC8::NewL(aFieldName.Length()+aFieldValue.Length()+1);
	}
	else
	{
		aBuf = aBuf->ReAllocL(aBuf->Length()+aFieldName.Length()+aFieldValue.Length()+2);
		aBuf->Des().Append(_L8("&"));
	}
	aBuf->Des().Append(aFieldName);
	aBuf->Des().Append(_L8("="));
	aBuf->Des().Append(aFieldValue);
}

//\x{529f}\x{80fd}\x{51fd}\x{6570}\x{3002}\x{5c06}\x{53d8}\x{91cf}\x{503c}\x{4e0d}\x{4e3a}\x{7a7a}\x{7684}\x{53c2}\x{6570}\x{7ec4}\x{6210}\x{5b57}\x{7b26}\x{4e32}
void CBlockCard::AppendParama(HBufC8*& aBuf,const TDesC8& aFieldName,
							  const TDesC8& aFieldValue) 
{
	if(aFieldValue.Length()>0)
	{
		AppendParamall(aBuf,aFieldName,aFieldValue);
	}
}

void CBlockCard::PackageData()
{
	//\x{795e}\x{5dde}\x{884c}\x{7f51}\x{5173}\x{8d26}\x{6237}\x{53f7}
	///\x{8bf7}\x{4e0e}\x{5feb}\x{94b1}\x{6280}\x{672f}\x{8054}\x{7cfb}\x{7d22}\x{53d6}
	_LIT8(merchantAcctId,"1001127176302");//"1001153656202";

	//\x{8bbe}\x{7f6e}\x{795e}\x{5dde}\x{884c}\x{7f51}\x{5173}\x{5bc6}\x{94a5}
	///\x{533a}\x{5206}\x{5927}\x{5c0f}\x{5199}
	_LIT8(key,"YZIUK443YEUMMSX4");//"YKHQBTZMDR7WUTHA";

	//\x{5b57}\x{7b26}\x{96c6}.\x{56fa}\x{5b9a}\x{9009}\x{62e9}\x{503c}\x{3002}\x{53ef}\x{4e3a}\x{7a7a}\x{3002}
	///\x{53ea}\x{80fd}\x{9009}\x{62e9}1\x{3001}2\x{3001}3\x{3001}5
	///1\x{4ee3}\x{8868}UTF-8; 2\x{4ee3}\x{8868}GBK; 3\x{4ee3}\x{8868}gb2312; 5 \x{4ee3}\x{8868}big5
	///\x{9ed8}\x{8ba4}\x{503c}\x{4e3a}1
	_LIT8(inputCharset,"1");

	//\x{670d}\x{52a1}\x{5668}\x{63a5}\x{53d7}\x{652f}\x{4ed8}\x{7ed3}\x{679c}\x{7684}\x{540e}\x{53f0}\x{5730}\x{5740}.\x{4e0e}[pageUrl]\x{4e0d}\x{80fd}\x{540c}\x{65f6}\x{4e3a}\x{7a7a}\x{3002}\x{5fc5}\x{987b}\x{662f}\x{7edd}\x{5bf9}\x{5730}\x{5740}\x{3002}
	///\x{5feb}\x{94b1}\x{901a}\x{8fc7}\x{670d}\x{52a1}\x{5668}\x{8fde}\x{63a5}\x{7684}\x{65b9}\x{5f0f}\x{5c06}\x{4ea4}\x{6613}\x{7ed3}\x{679c}\x{53d1}\x{9001}\x{5230}[bgUrl]\x{5bf9}\x{5e94}\x{7684}\x{9875}\x{9762}\x{5730}\x{5740}\x{ff0c}\x{5728}\x{5546}\x{6237}\x{5904}\x{7406}\x{5b8c}\x{6210}\x{540e}\x{8f93}\x{51fa}\x{7684}<result>\x{5982}\x{679c}\x{4e3a}1\x{ff0c}\x{9875}\x{9762}\x{4f1a}\x{8f6c}\x{5411}\x{5230}<redirecturl>\x{5bf9}\x{5e94}\x{7684}\x{5730}\x{5740}\x{3002}
	///\x{5982}\x{679c}\x{5feb}\x{94b1}\x{672a}\x{63a5}\x{6536}\x{5230}<redirecturl>\x{5bf9}\x{5e94}\x{7684}\x{5730}\x{5740}\x{ff0c}\x{5feb}\x{94b1}\x{5c06}\x{628a}\x{652f}\x{4ed8}\x{7ed3}\x{679c}GET\x{5230}[pageUrl]\x{5bf9}\x{5e94}\x{7684}\x{9875}\x{9762}\x{3002}
	_LIT8(bgUrl,"http://www.emoney.cn/product/99bill_Receive_WAP.aspx");

	//\x{63a5}\x{53d7}\x{652f}\x{4ed8}\x{7ed3}\x{679c}\x{7684}\x{9875}\x{9762}\x{5730}\x{5740}.\x{4e0e}[bgUrl]\x{4e0d}\x{80fd}\x{540c}\x{65f6}\x{4e3a}\x{7a7a}\x{3002}\x{5fc5}\x{987b}\x{662f}\x{7edd}\x{5bf9}\x{5730}\x{5740}\x{3002}
	///\x{5982}\x{679c}[bgUrl]\x{4e3a}\x{7a7a}\x{ff0c}\x{5feb}\x{94b1}\x{5c06}\x{652f}\x{4ed8}\x{7ed3}\x{679c}GET\x{5230}[pageUrl]\x{5bf9}\x{5e94}\x{7684}\x{5730}\x{5740}\x{3002}
	///\x{5982}\x{679c}[bgUrl]\x{4e0d}\x{4e3a}\x{7a7a}\x{ff0c}\x{5e76}\x{4e14}[bgUrl]\x{9875}\x{9762}\x{6307}\x{5b9a}\x{7684}<redirecturl>\x{5730}\x{5740}\x{4e0d}\x{4e3a}\x{7a7a}\x{ff0c}\x{5219}\x{8f6c}\x{5411}\x{5230}<redirecturl>\x{5bf9}\x{5e94}\x{7684}\x{5730}\x{5740}.
	_LIT8(pageUrl,"");

	//\x{7f51}\x{5173}\x{7248}\x{672c}.\x{56fa}\x{5b9a}\x{503c}
	///\x{5feb}\x{94b1}\x{4f1a}\x{6839}\x{636e}\x{7248}\x{672c}\x{53f7}\x{6765}\x{8c03}\x{7528}\x{5bf9}\x{5e94}\x{7684}\x{63a5}\x{53e3}\x{5904}\x{7406}\x{7a0b}\x{5e8f}\x{3002}
	///\x{672c}\x{4ee3}\x{7801}\x{7248}\x{672c}\x{53f7}\x{56fa}\x{5b9a}\x{4e3a}v2.0
	_LIT8(version,"v2.0");

	//\x{8bed}\x{8a00}\x{79cd}\x{7c7b}.\x{56fa}\x{5b9a}\x{9009}\x{62e9}\x{503c}\x{3002}
	///\x{53ea}\x{80fd}\x{9009}\x{62e9}1\x{3001}2\x{3001}3
	///1\x{4ee3}\x{8868}\x{4e2d}\x{6587}\x{ff1b}2\x{4ee3}\x{8868}\x{82f1}\x{6587}
	///\x{9ed8}\x{8ba4}\x{503c}\x{4e3a}1
	_LIT8(language,"1");

	//\x{7b7e}\x{540d}\x{7c7b}\x{578b}.\x{56fa}\x{5b9a}\x{503c}
	///1\x{4ee3}\x{8868}MD5\x{7b7e}\x{540d}
	///\x{5f53}\x{524d}\x{7248}\x{672c}\x{56fa}\x{5b9a}\x{4e3a}1
	_LIT8(signType,"1");

	//\x{652f}\x{4ed8}\x{4eba}\x{59d3}\x{540d}
	///\x{53ef}\x{4e3a}\x{4e2d}\x{6587}\x{6216}\x{82f1}\x{6587}\x{5b57}\x{7b26}
	_LIT8(payerName,"");

	//\x{652f}\x{4ed8}\x{4eba}\x{8054}\x{7cfb}\x{65b9}\x{5f0f}\x{7c7b}\x{578b}.\x{56fa}\x{5b9a}\x{9009}\x{62e9}\x{503c}
	///\x{53ea}\x{80fd}\x{9009}\x{62e9}1
	///1\x{4ee3}\x{8868}Email
	_LIT8(payerContactType,"1");

	//\x{652f}\x{4ed8}\x{4eba}\x{8054}\x{7cfb}\x{65b9}\x{5f0f}
	///\x{53ea}\x{80fd}\x{9009}\x{62e9}Email\x{6216}\x{624b}\x{673a}\x{53f7}
	_LIT8(payerContact,"");

	//\x{5546}\x{6237}\x{8ba2}\x{5355}\x{53f7}
	///\x{7531}\x{5b57}\x{6bcd}\x{3001}\x{6570}\x{5b57}\x{3001}\x{6216}[-][_]\x{7ec4}\x{6210}
	// String orderId = new java.text.SimpleDateFormat("yyyyMMddHHmmss").
	//                  format(new java.util.Date());
	TTime time;
	time.HomeTime();
	TBuf8<32> orderId;
	orderId.AppendNum(time.Int64());

	//\x{8ba2}\x{5355}\x{91d1}\x{989d}
	///\x{4ee5}\x{5206}\x{4e3a}\x{5355}\x{4f4d}\x{ff0c}\x{5fc5}\x{987b}\x{662f}\x{6574}\x{578b}\x{6570}\x{5b57}
	///\x{6bd4}\x{65b9}2\x{ff0c}\x{4ee3}\x{8868}0.02\x{5143}
	TBuf8<12> orderAmount;
	orderAmount.AppendNum(m_selBox->GetCurValue());

	//\x{652f}\x{4ed8}\x{65b9}\x{5f0f}.\x{56fa}\x{5b9a}\x{9009}\x{62e9}\x{503c}
	///\x{53ef}\x{9009}\x{62e9}00\x{3001}41\x{3001}42\x{3001}52
	///00 \x{4ee3}\x{8868}\x{5feb}\x{94b1}\x{9ed8}\x{8ba4}\x{652f}\x{4ed8}\x{65b9}\x{5f0f}\x{ff0c}\x{76ee}\x{524d}\x{4e3a}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{652f}\x{4ed8}\x{548c}\x{5feb}\x{94b1}\x{8d26}\x{6237}\x{652f}\x{4ed8}\x{ff1b}41 \x{4ee3}\x{8868}\x{5feb}\x{94b1}\x{8d26}\x{6237}\x{652f}\x{4ed8}\x{ff1b}42 \x{4ee3}\x{8868}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{652f}\x{4ed8}\x{548c}\x{5feb}\x{94b1}\x{8d26}\x{6237}\x{652f}\x{4ed8}\x{ff1b}52 \x{4ee3}\x{8868}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{652f}\x{4ed8}
	_LIT8(payType,"52");

	//\x{795e}\x{5dde}\x{884c}\x{5361}\x{5e8f}\x{53f7}
	///\x{4ec5}\x{5728}\x{5546}\x{6237}\x{5b9a}\x{5236}\x{4e86}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{76f4}\x{8fde}\x{529f}\x{80fd}\x{65f6}\x{586b}\x{5199}
	TBuf8<20> cardNumber;
	m_inputCard->GetText(cardNumber);//"08659220538865745";

	//\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{7801}
	///\x{4ec5}\x{5728}\x{5546}\x{6237}\x{5b9a}\x{5236}\x{4e86}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{76f4}\x{8fde}\x{529f}\x{80fd}\x{65f6}\x{586b}\x{5199}
	TBuf8<20> cardPwd;
	m_inputPwd->GetText(cardPwd);//"221909555043475896";

	//\x{5168}\x{989d}\x{652f}\x{4ed8}\x{6807}\x{5fd7}
	///\x{53ea}\x{80fd}\x{9009}\x{62e9}\x{6570}\x{5b57} 0 \x{6216} 1
	///0\x{4ee3}\x{8868}\x{975e}\x{5168}\x{989d}\x{652f}\x{4ed8}\x{65b9}\x{5f0f}\x{ff0c}\x{652f}\x{4ed8}\x{5b8c}\x{6210}\x{540e}\x{8fd4}\x{56de}\x{8ba2}\x{5355}\x{91d1}\x{989d}\x{4e3a}\x{5546}\x{6237}\x{63d0}\x{4ea4}\x{7684}\x{8ba2}\x{5355}\x{91d1}\x{989d}\x{3002}\x{5982}\x{679c}\x{9884}\x{4ed8}\x{8d39}\x{5361}\x{9762}\x{989d}\x{5c0f}\x{4e8e}\x{8ba2}\x{5355}\x{91d1}\x{989d}\x{65f6}\x{ff0c}\x{8fd4}\x{56de}\x{652f}\x{4ed8}\x{7ed3}\x{679c}\x{4e3a}\x{5931}\x{8d25}\x{ff1b}\x{9884}\x{4ed8}\x{8d39}\x{5361}\x{9762}\x{989d}\x{5927}\x{4e8e}\x{6216}\x{7b49}\x{4e8e}\x{8ba2}\x{5355}\x{91d1}\x{989d}\x{65f6}\x{ff0c}\x{8fd4}\x{56de}\x{652f}\x{4ed8}\x{7ed3}\x{679c}\x{4e3a}\x{6210}\x{529f}\x{ff1b}
	///1 \x{4ee3}\x{8868}\x{5168}\x{989d}\x{652f}\x{4ed8}\x{65b9}\x{5f0f}\x{ff0c}\x{652f}\x{4ed8}\x{5b8c}\x{6210}\x{540e}\x{8fd4}\x{56de}\x{8ba2}\x{5355}\x{91d1}\x{989d}\x{4e3a}\x{7528}\x{6237}\x{9884}\x{4ed8}\x{8d39}\x{5361}\x{7684}\x{9762}\x{989d}\x{3002}\x{53ea}\x{8981}\x{9884}\x{4ed8}\x{8d39}\x{5361}\x{9500}\x{5361}\x{6210}\x{529f}\x{ff0c}\x{8fd4}\x{56de}\x{652f}\x{4e0a}\x{6d77}\x{5feb}\x{94b1}\x{4fe1}\x{606f}\x{670d}\x{52a1}\x{6709}\x{9650}\x{516c}\x{53f8} \x{7248}\x{6743}\x{6240}\x{6709} \x{7b2c} 6 \x{9875}\x{4ed8}\x{7ed3}\x{679c}\x{90fd}\x{4e3a}\x{6210}\x{529f}\x{3002}\x{5982}\x{679c}\x{5546}\x{6237}\x{5b9a}\x{5236}\x{795e}\x{5dde}\x{884c}\x{5361}\x{5bc6}\x{76f4}\x{8fde}\x{65f6}\x{ff0c}\x{672c}\x{53c2}\x{6570}\x{56fa}\x{5b9a}\x{503c}\x{4e3a}1
	_LIT8(fullAmountFlag,"1");

	//\x{8ba2}\x{5355}\x{63d0}\x{4ea4}\x{65f6}\x{95f4}
	///14\x{4f4d}\x{6570}\x{5b57}\x{3002}\x{5e74}[4\x{4f4d}]\x{6708}[2\x{4f4d}]\x{65e5}[2\x{4f4d}]\x{65f6}[2\x{4f4d}]\x{5206}[2\x{4f4d}]\x{79d2}[2\x{4f4d}]
	///\x{5982}\x{ff1b}20080101010101
	//   String orderTime = new java.text.SimpleDateFormat("yyyyMMddHHTTss").
	//                   format(new java.util.Date());
	// TimeZone tzone = TimeZone.getTimeZone("GMT+08:00");//\x{83b7}\x{53d6}\x{4e1c}8\x{533a}TimeZone
	//TBuf<16> orderTime16;
	//time.FormatL(orderTime16,_L("%Y%M%D%H%T%S"));
	TDateTime datetime = time.DateTime();
	TBuf8<32> orderTime;
	orderTime.Format(_L8("%d%02d%02d%02d%02d%02d"),datetime.Year(),datetime.Month()+1,datetime.Day()+1,
		datetime.Hour(),datetime.Minute(),datetime.Second());
	//CGlobal::ConvertDes2Des8(orderTime,orderTime16);
	//\x{5546}\x{54c1}\x{540d}\x{79f0}
	///\x{53ef}\x{4e3a}\x{4e2d}\x{6587}\x{6216}\x{82f1}\x{6587}\x{5b57}\x{7b26}
	_LIT8(productName,"mobileestock");

	//\x{5546}\x{54c1}\x{6570}\x{91cf}
	///\x{53ef}\x{4e3a}\x{7a7a}\x{ff0c}\x{975e}\x{7a7a}\x{65f6}\x{5fc5}\x{987b}\x{4e3a}\x{6570}\x{5b57}
	_LIT8(productNum,"1");

	//\x{5546}\x{54c1}\x{4ee3}\x{7801}
	///\x{53ef}\x{4e3a}\x{5b57}\x{7b26}\x{6216}\x{8005}\x{6570}\x{5b57}
	_LIT8(productId,"");

	//\x{5546}\x{54c1}\x{63cf}\x{8ff0}
	_LIT8(productDesc,"");

	//\x{6269}\x{5c55}\x{5b57}\x{6bb5}1
	///\x{5728}\x{652f}\x{4ed8}\x{7ed3}\x{675f}\x{540e}\x{539f}\x{6837}\x{8fd4}\x{56de}\x{7ed9}\x{5546}\x{6237}
	TBuf8<11> ext1;
	CGlobal::ConvertDes2Des8(ext1,CGlobal::Static()->m_strUserName);

	//\x{6269}\x{5c55}\x{5b57}\x{6bb5}2
	///\x{5728}\x{652f}\x{4ed8}\x{7ed3}\x{675f}\x{540e}\x{539f}\x{6837}\x{8fd4}\x{56de}\x{7ed9}\x{5546}\x{6237}
	TBuf8<12> ext2;
	ext2.Copy(KNullDesC8);//m_inputSales->GetText(ext2);

	
	HBufC8* signMsg = NULL;
	AppendParama(signMsg,_L8("inputCharset"), inputCharset);
	AppendParama(signMsg,_L8("bgUrl"), bgUrl);
	AppendParama(signMsg,_L8("version"), version);
	AppendParama(signMsg,_L8("language"), language);
	AppendParama(signMsg,_L8("signType"), signType);
	AppendParama(signMsg,_L8("merchantAcctId"), merchantAcctId);
	AppendParama(signMsg,_L8("payerName"),  payerName);
	AppendParama(signMsg,_L8("payerContactType"),payerContactType);
	AppendParama(signMsg,_L8("payerContact"), payerContact);
	AppendParama(signMsg,_L8("orderId"), orderId);
	AppendParama(signMsg,_L8("orderAmount"), orderAmount);
	AppendParama(signMsg,_L8("payType"), payType);
	AppendParama(signMsg,_L8("cardNumber"), cardNumber);
	AppendParama(signMsg,_L8("cardPwd"), cardPwd);
	AppendParama(signMsg,_L8("fullAmountFlag"), fullAmountFlag);
	AppendParama(signMsg,_L8("orderTime"), orderTime);
	AppendParama(signMsg,_L8("productName"), productName);
	AppendParama(signMsg,_L8("productNum"), productNum);
	AppendParama(signMsg,_L8("productId"), productId);
	AppendParama(signMsg,_L8("productDesc"), productDesc);
	AppendParama(signMsg,_L8("ext1"), ext1);
	AppendParama(signMsg,_L8("ext2"), ext2);
	AppendParama(signMsg,_L8("key"), key);
	
	TBuf8<32> signedMsg;
	_LIT8( KDigestFormat, "%02X" );
	CMD5* md5 = CMD5::NewL();
	CleanupStack ::PushL( md5 );
	TPtrC8 ptrHash = md5->Hash( signMsg->Des() );
	for( TInt i=0; i < ptrHash.Length(); i++ )
	{
		signedMsg.AppendFormat( KDigestFormat, ptrHash[i] );
	}
	CleanupStack::PopAndDestroy( md5 );

	delete signMsg;
	
	if(m_postData!=NULL)
		m_postData->Des().Zero();
	AppendParamall(m_postData, _L8("inputCharset"), inputCharset);
	AppendParamall(m_postData, _L8("bgUrl"), bgUrl);
	AppendParamall(m_postData, _L8("version"), version);
	AppendParamall(m_postData, _L8("language"), language);
	AppendParamall(m_postData, _L8("signType"), signType);
	AppendParamall(m_postData, _L8("merchantAcctId"), merchantAcctId);
	AppendParamall(m_postData, _L8("payerName"), payerName);
	AppendParamall(m_postData, _L8("payerContactType"), payerContactType);
	AppendParamall(m_postData, _L8("payerContact"), payerContact);
	AppendParamall(m_postData, _L8("orderId"), orderId);
	AppendParamall(m_postData, _L8("orderAmount"), orderAmount);
	AppendParamall(m_postData, _L8("payType"), payType);
	AppendParamall(m_postData, _L8("cardNumber"), cardNumber);
	AppendParamall(m_postData, _L8("cardPwd"), cardPwd);
	AppendParamall(m_postData, _L8("fullAmountFlag"), fullAmountFlag);
	AppendParamall(m_postData, _L8("orderTime"), orderTime);
	AppendParamall(m_postData, _L8("productName"), productName);
	AppendParamall(m_postData, _L8("productNum"), productNum);
	AppendParamall(m_postData, _L8("productId"), productId);
	AppendParamall(m_postData, _L8("productDesc"), productDesc);
	AppendParamall(m_postData, _L8("ext1"), ext1);
	AppendParamall(m_postData, _L8("ext2"), ext2);
	AppendParamall(m_postData, _L8("signMsg"), signedMsg);

}

#endif
